This repository was archived by the owner on May 20, 2025. It is now read-only.
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Member
|
Tested it with an OpenAPI Key - { Updated code: import os
from openai import OpenAI
from nitric.resources import api
from nitric.application import Nitric
from nitric.context import HttpContext
# Configure OpenAI API key from env
api_key = os.environ.get("OPENAI_API_KEY")
if not api_key:
raise Exception("Please set the OPENAI_API_KEY environment variable")
# Create OpenAI client
client = OpenAI(api_key=api_key)
# Define Nitric API
summarize_api = api("main")
@summarize_api.post("/summarize")
async def summarize_text(ctx: HttpContext) -> None:
req_data = ctx.req.json
if not req_data or 'text' not in req_data:
ctx.res.status = 400
ctx.res.body = {"error": "No text provided for summarization."}
return
text_to_summarize = req_data['text']
try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": f"Summarize the following text:\n\n{text_to_summarize}"}],
max_tokens=50
)
summary = response.choices[0].message.content
ctx.res.body = {"summary": summary.strip()}
except Exception as e:
ctx.res.status = 500
ctx.res.body = {"error": str(e)}
Nitric.run() |
raksiv
suggested changes
Apr 3, 2025
Member
raksiv
left a comment
There was a problem hiding this comment.
Update code to deal with deprecations.
davemooreuws
suggested changes
Apr 4, 2025
davemooreuws
reviewed
Apr 8, 2025
davemooreuws
previously approved these changes
Apr 8, 2025
HomelessDinosaur
suggested changes
Apr 8, 2025
tjholm
reviewed
Apr 8, 2025
HomelessDinosaur
suggested changes
May 2, 2025
Co-authored-by: Ryan Cartwright <39504851+HomelessDinosaur@users.noreply.github.com>
4c66c42 to
908289e
Compare
Co-authored-by: Ryan Cartwright <39504851+HomelessDinosaur@users.noreply.github.com>
davemooreuws
reviewed
May 8, 2025
HomelessDinosaur
previously approved these changes
May 8, 2025
davemooreuws
reviewed
May 8, 2025
HomelessDinosaur
approved these changes
May 8, 2025
tjholm
approved these changes
May 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.